package com.bdqn.zhang.dao.impl;

import com.bdqn.zhang.dao.UserDao;
import com.bdqn.zhang.pojo.Sysuser;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository("userDao")
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

    @Resource(name = "sessionFactory")
    public void setSessionFactoryOverride(SessionFactory sessionFactory) {
        super.setSessionFactory(sessionFactory);
    }

    @Override
    public Sysuser findUser(String username, String password) {
        List<Sysuser> list = (List<Sysuser>)this.getHibernateTemplate().find("from Sysuser where username = ? and password = ?", username, password);
        if(list != null && list.size() > 0){
            return list.get(0);
        }
        return null;
    }
}
